package com.ihelin.insurance.config;

import com.ihelin.insurance.interceptor.AdminUserInterceptor;
import com.ihelin.insurance.interceptor.AgentInterceptor;
import com.ihelin.insurance.interceptor.SalesInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author iHelin
 * @since 2021/2/27 14:11
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index").setViewName("index");
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new AdminUserInterceptor())
            .addPathPatterns("/admin/**");
        registry.addInterceptor(new AgentInterceptor()).addPathPatterns("/agent/**");
        registry.addInterceptor(new SalesInterceptor()).addPathPatterns("/sales/**");
//        registry.excludePathPatterns("/payed/notify","/error");
    }
}
